<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>星型图案</title>
    <link rel="stylesheet" href="test01.css">

</head>
<body>
    <div class="container" id="diamondPattern"></div>
    <script>
        const container = document.getElementById('diamondPattern');
        let patternContent = '';
        const rows = 5;
        for (let i = 1; i <= rows; i++) {
            for (let k = 1; k <= rows - i; k++) {
                patternContent += '&nbsp;';
            }
            for (let j = 1; j <= 2 * i - 1; j++) {
                patternContent += '*';
            }
            patternContent += '<br>';
        }
        for (let i = rows - 1; i >= 1; i--) {
            for (let k = 1; k <= rows - i; k++) {
                patternContent += '&nbsp;';
            }
            for (let j = 1; j <= 2 * i - 1; j++) {
                patternContent += '*';
            }
            patternContent += '<br>';
        }
        container.innerHTML = patternContent;
    </script>
</body>
</html>